package day0927;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * You are given the ages (in years) of allpeople of a country with 
 * at least 1 year of age.
 * You know that no individual in that country lives for 100 or more years. 
 * Now, you are given a very simple task of sorting all the ages in ascending order.
 * @author chenxiaokang
 *
 */

public class Ques1030MergeSort {
	
	public void mergeSort(int[] arr,int n){
		this.mergeSort(arr,0,n-1);
	}
	
	private void mergeSort(int[] arr,int l,int r){
		
		if(l >= r)return;
		
//		if( l - r <= 15){
//			insertionSort(arr,l,r);
//			return;
//		}
		
		int mid = (l + r)/2;
		this.mergeSort(arr,l,mid);
		this.mergeSort(arr,mid+1,r);
		if(arr[mid] > arr[mid + 1])
			this.merge(arr,l,mid,r);
	}
	
	private void merge(int[] arr,int l,int mid,int r){
		int[] temp = new int[r - l + 1];
		for(int i = l;i <= r; i++){
			temp[i - l] = arr[i];
		}
		
		int i = l,j = mid + 1;
		
		for(int k = l;k <=r;k ++){
			if(i > mid){
				arr[k] = temp[j - l];
				j++;
			}else if(j > r){
				arr[k] = temp[i - l];
				i++;
			}else if(temp[i - l] < temp[j -l]){
				arr[k] = temp[i-l];
				i ++;
			}else{
				arr[k] = temp[j - l];
				j ++;
			}
		}
	}

		public static void main(String[] args) {
			Scanner scan = new Scanner(System.in);
			int n = 0;
			int[] scoreList;
			List<String> resultList = new ArrayList<String>();
			while(scan.hasNext()){
				n = scan.nextInt();
				if( n == 0){
					for(String str : resultList){
						System.out.println(str);
					}
					return;
				}
				scoreList = new int[n];
				for(int i = 0;i < n;i++){
					scoreList[i] = scan.nextInt();
				}
				new Ques1030MergeSort().mergeSort(scoreList, n);
				String result = "";
				for(int i : scoreList){
					result += i+" ";
				}
				result = result.substring(0, result.length() - 1);
				resultList.add(result);
		}
	}
}
